local rule = fk.CreateSkill {
  name = "md_mode",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["md_mode"] = "幻化",
  [":md_mode"] = "施咒技，锁定技，当一名角色受到一点伤害后，可以从剩余武将牌堆中随机获得一张武将牌作为副将。",
  ["md_sgsh_deputy"] = "副将",
  ["#sgsh-deputy"] = "是否要获得副将？",
}

local U = require "packages/modify/ofl_util"

rule:addEffect(fk.Damaged, {
  priority = 0.001,
  trigger_times = function(self, event, target, player, data)
    return data.damage
  end,
  can_trigger = function(self, event, target, player, data)
    return target == player and not player.dead
  end,
  on_trigger = function(self, event, target, player, data)
      U.sgshAcquireDeputy(player)
  end,
})

rule:addEffect(fk.Death, {
  late_refresh = true,
  can_refresh = function (self, event, target, player, data)
    return target == player
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    table.insertIfNeed(room.general_pile, player.general)
    table.insertTableIfNeed(room.general_pile, player:getTableMark("md_sgsh_deputy"))
  end,
})



return rule
